package cn.bytecollege.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**
 * 用于生成验证码
 */
@Controller
@RequestMapping("/valid")
public class ValidCodeController {
    @GetMapping("/valid")
    public void validCode(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException {
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 100, 4, 4);
        captcha.write(response.getOutputStream());

        String code = captcha.getCode();

        session.setAttribute("code", code);
    }
}

